package com.hl.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.ChargeType;
import com.hl.sfzy.service.ChargeTypeService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chargeType")
@CrossOrigin
public class ChargeTypeController {
    @Autowired
    private ChargeTypeService chargeTypeService;
    @RequestMapping("/selectAll")
    public R selectAll(){
        List<ChargeType> list = chargeTypeService.selectAll();
        return R.ok(list);
    }
    @GetMapping("/findByPage")
    public R findByPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                        @RequestParam(required = false,defaultValue = "3") int pageSize,
                        ChargeType chargeType){
        PageInfo<ChargeType> pageInfo=chargeTypeService.findByPage(pageNum, pageSize, chargeType);
        return R.ok(pageInfo);
    }
    @RequestMapping("/selectById")
    public R selectById(long id){
        return R.ok(chargeTypeService.selectByPrimaryKey(id));
    }
    @PostMapping("/insert")
    public R insert(@RequestBody ChargeType chargeType){
        return R.ok(chargeTypeService.insert(chargeType));
    }
    @DeleteMapping("/delete")
    public R delete(long id){
        return R.ok(chargeTypeService.deleteByPrimaryKey(id));
    }
    @PutMapping("/update")
    public R update(@RequestBody ChargeType chargeType){
        return R.ok(chargeTypeService.update(chargeType));
    }
}
